Skip to content

feat: expose oauth discovery metadata source#1041

Open
DaleSeo wants to merge 2 commits into
mainfrom
fix/oauth-discovery-metadata-source
Open

feat: expose oauth discovery metadata source#1041
DaleSeo wants to merge 2 commits into
mainfrom
fix/oauth-discovery-metadata-source

Conversation

@DaleSeo

@DaleSeo DaleSeo commented Jul 24, 2026

Copy link
Copy Markdown
Member

Closes #1037

Motivation and Context

AuthorizationManager::discover_metadata() falls back to the legacy default endpoints, /authorize, /token, and /register, based on the base URL when discovery returns nothing. This fallback is required for the auth/2025-03-26-oauth-endpoint-fallback conformance scenario. However, it makes a successful fallback look the same as metadata that the server actually published. As a result, callers cannot tell whether OAuth metadata was discovered or synthesized for compatibility. That behavior was originally introduced in #507 and changed by #960.

This changes AuthorizationManager::discover_metadata() itself to return DiscoveredAuthorizationMetadata, which contains both the AuthorizationMetadata and its AuthorizationMetadataSource. The source distinguishes protected resource metadata, authorization server metadata, and the legacy endpoint fallback; is_discovered() reports whether the server published metadata.

Because v3 is still in beta, this makes provenance part of the primary discovery contract now instead of adding a parallel method that would need to be retained long-term. Internal SDK and conformance call sites explicitly extract .metadata; the discovery order, legacy endpoint synthesis, and conformance behavior remain unchanged.

How Has This Been Tested?

Unit tests cover all three sources

Breaking Changes

AuthorizationManager::discover_metadata() now returns Result<DiscoveredAuthorizationMetadata, AuthError> instead of Result<AuthorizationMetadata, AuthError>.

Callers that need the metadata directly must extract the metadata field:

// Before
let metadata = manager.discover_metadata().await?;
manager.set_metadata(metadata);

// After
let discovered = manager.discover_metadata().await?;
manager.set_metadata(discovered.metadata);

Callers can inspect discovered.source or call discovered.source.is_discovered() before consuming the metadata.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@github-actions github-actions Bot added T-core Core library changes T-transport Transport layer changes labels Jul 24, 2026
@DaleSeo DaleSeo self-assigned this Jul 24, 2026
@DaleSeo
DaleSeo marked this pull request as ready for review July 24, 2026 03:31
@DaleSeo
DaleSeo requested a review from a team as a code owner July 24, 2026 03:31
jamadeo
jamadeo previously approved these changes Jul 24, 2026
/// Nothing was discovered; the endpoints were synthesized from the base
/// URL (`/authorize`, `/token`, `/register`) for compatibility with the
/// 2025-03-26 MCP spec's default-endpoint fallback. The server gave no
/// evidence that it supports OAuth.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would include something here if we're going to have a descriptive comment that metadata discovery is now mandatory in newer versions of the spec, and there is no endpoint-synthesis fallback any more.

https://modelcontextprotocol.io/specification/draft/basic/authorization/authorization-server-discovery#protected-resource-metadata-discovery-requirements

@github-actions github-actions Bot added the T-documentation Documentation improvements label Jul 24, 2026
@DaleSeo
DaleSeo force-pushed the fix/oauth-discovery-metadata-source branch from 37d76ac to 379be61 Compare July 24, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth discovery should distinguish discovered authorization metadata from synthesized legacy endpoints

3 participants